package com.yangfan.screenshot.utils;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.view.WindowManager;

import androidx.annotation.NonNull;

/**
 * @author : yangfan_rj
 * @date : 2022/12/8-20:57
 * desc   : 屏幕工具
 */
public class ScreenUtil {
    public static final ScreenUtil instance = new ScreenUtil();
    private Context mContext = null;

    private ScreenUtil() {
    }

    public void init(Context context) {
        mContext = context;
    }

    public final int getNavigationBarHeight() {
        Resources system = Resources.getSystem();
        return system.getDimensionPixelSize(system.getIdentifier("navigation_bar_height", "dimen", "android"));
    }

    public final int getStatusBarHeight() {
        Resources system = Resources.getSystem();
        return system.getDimensionPixelSize(system.getIdentifier("status_bar_height", "dimen", "android"));
    }

    public final int getHeight() {
        WindowManager windowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
        Point point = new Point();
        windowManager.getDefaultDisplay().getRealSize(point);
        return point.y;
    }

    public final int getWidth() {
        WindowManager windowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
        Point point = new Point();
        windowManager.getDefaultDisplay().getRealSize(point);
        return point.x;
    }
}
